<?php
/**
 * Desc:
 * Author:Oven
 * Date: 2017/7/28
 */

class FeedbackTypesModel extends CscModel{
    public static function model( $className=__CLASS__ ) {
        return parent::model( $className );
    }

    static $_instance =null;
    public static function  create(){
        if(null=== self::$_instance){
            self::$_instance = new self;
        }
        return self::$_instance;
    }
    public function getDbConnection($db="user") {
        return Yii::app()->$db;
    }

    public function tableName() {
        return '{{feedback_types}}';
    }

    public function get_all($where = " parent_id = 0 AND state = 2 "){
        $list = $this->fetchAll($where,0,1000," sort ASC ");
        $data = [];
        if(count($list)){
            foreach($list as $row){
                $_data["title"] = $row["name"];
                $_data["describe"] = $row["describe"];
                $_data["id"] = StringProcXHelpers::StringProcX($row["id"],"ENCODE");
                $_data['children'] = $this->get_all("parent_id = '{$row["id"]}' AND state = 2 ");
                $data[] = $_data;
            }
        }
        return $data;
    }

    public function getKV($where = "  1=1 "){
        $list = $this->fetchAll($where ,0,1000);
        $data = [];
        foreach ($list as $row) {
            $data[$row["id"]] = $row["title"];
        }
        return $data;
    }
}